﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MS.InformationManagement.Support;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Presenter.ConfirmationMessage;


namespace MS.InformationManagement.WP.Layouts.MS.InformationManagement.WP
{
    public partial class ConfirmationMessage : LayoutsPageBase, IConfirmationMessageView
    {
        #region fields

        private ConfirmationMessagePresenter _presenter;

        #endregion

        #region Properties

        public int CurrentId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["ID"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["ID"]);
            }
        }
        public int IsCopy
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["IsCopy"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["IsCopy"]);
            }
        }
        public Guid CurrentListId
        {
            get
            {
                return new Guid(Page.Request.QueryString["List"]);
            }
        }
        public string Strategy
        {
            get { return Page.Request.QueryString["strategy"]; }
        }
        public bool Result { get; set; }
        public int IdDevolucion
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["IdDevolucion"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["IdDevolucion"]);
            }
        }

        #endregion

        #region Form Events
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btnCancelarAccion.Click += new EventHandler(btnCancelarAccion_Click);
            btnSucced.Click += new EventHandler(btnSucced_Click);
        }

        void btnSucced_Click(object sender, EventArgs e)
        {
            if (Strategy == "SendToPrint")
                _presenter.SentToPrint();
            
        }

        void btnCancelarAccion_Click(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            _presenter = new ConfirmationMessagePresenter(this);
            if (Strategy == "SendToPrint")
                lblObservaciones.Text = "Esta seguro que ha modificado correctamente los datos del destinatario.";

        }
        
        #endregion

        #region Implemented Methods

        public void Success()
        {
            if (Result == true)
            {
                this._ShowAlertAndClose("Su solicitud ha sido exitosa");
            }
            else
            {
                btnCancelarAccion.Enabled = false;
                btnSucced.Enabled = false;
                this._ShowAlertAndClose("Ha ocurrido un error.");
            }

        }

        #endregion
    }
}
